package com.cloud.common;

/**
 * @Author tangyuan2meicloud.com
 * @DATE 2021/7/7 11:32
 * @Desc
 * @Remarks
 */
public class R<T> {

    private Integer code;
    private String msg;
    private T data;

    public R() {
    }

    public R(Builder<T> builder) {
        this.code = builder.code;
        this.msg = builder.msg;
        this.data = builder.data;
    }

    public static class Builder<T> {
        private Integer code;
        private String msg;
        private T data;

        public Builder() {
        }
        public R buildCustomize(int code,String msg){
            this.code=code;
            this.msg=msg;
            return new R(this);
        }
        public R buildCustomize(String msg){
            this.code=-1;
            this.msg=msg;
            return new R(this);
        }
        public R buildOk(){
            this.code=200;
            this.msg="success";
            return new R(this);
        }
        public R buildFail(){
            this.code=-1;
            this.msg="failed";
            return new R(this);
        }

        public Builder setData(T data){
            this.data=data;
            return this;
        }
    }

    public R(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public Integer getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }

    public T getData() {
        return data;
    }
}
